﻿using BBICMS.Model;
using BBICMS.Model.ViewModel.Front;
using BBICMS.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace BBICMS.WebUI.Controllers
{
    public class LinkController : Controller
    {
        private ApplicationUnit _unit = new ApplicationUnit();
        //
        // GET: /Link/

        public ActionResult Index(int? categoryId)
        {
            IEnumerable<Link> lLinks = _unit.Links.GetAll().Where(p => p.Active == true);

            if(categoryId>0)
                    lLinks = lLinks.Where(l=>l.CategoryId == categoryId);

            LinkListVM vm = new LinkListVM();

            vm.Categories = (from lc in this._unit.LinkCategories.GetAll()
                        orderby lc.Importance descending
                        select lc).ToList();

            vm.Links = lLinks.OrderByDescending(p => p.Importance).ThenByDescending(l => l.AddedDate);


            return View(vm);
       
        }

    }
}
